# coding:utf-8

import urllib2
import random

ua_list = [
    "Mozilla/5.0 (Windows NT 6.1; ) Apple.... ",
    "Mozilla/5.0 (X11; CrOS i686 2268.111.0)... ",
    "Mozilla/5.0 (Macintosh; U; PPC Mac OS X.... ",
    "Mozilla/5.0 (Macintosh; Intel Mac OS... "
]

request = urllib2.Request('http://www.baidu.com/')
request.add_header('Connection','keep-alive')
ua = random.choice(ua_list)
request.add_header('User-Agent',str(ua))
print(ua)

print(request.get_header('Connection'))
print(request.get_header('User-Agent'))

# print urllib2.urlopen(request).read()